//
//  ViewController.m
//  UIImage程序
//
//  Created by mir_yan on 2018/10/2.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import "ViewController.h"
#import "ChatBubble.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 圆角
    UIView* redView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    redView.backgroundColor = [UIColor redColor];
    redView.layer.cornerRadius = 50;
    redView.layer.borderWidth = 3.0;
    redView.layer.borderColor = [UIColor blueColor].CGColor;
    
    /**
        1 应用程序束
        2 沙箱 安全目录 可读可写 Documents/Library/temp
     */
    
    // 1、读取本地文件的方式
    NSString* fileName = [[NSBundle mainBundle] pathForResource:@"swiper" ofType:@"png"];
    NSData* imgData = [NSData dataWithContentsOfFile:fileName];
    UIImage* image = [UIImage imageWithData:imgData];
    
    // png pdf 可以省略
    // 2、使用图片频率特别高的时候使用
//    UIImage* image = [UIImage imageNamed:@"swiper.png"];
    
    // 3、网络 TODO 没讲为啥加载不出来
//    NSString* urlString = @"http://img4.imgtn.bdimg.com/it/u=1926421234,1074130284&fm=27&gp=0.jpg";
//    NSURL* url = [NSURL URLWithString:urlString];
//    NSData* data = [NSData dataWithContentsOfURL:url];
//    UIImage* image = [UIImage imageWithData:data];
    
    // 加载图片
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 100, CGRectGetWidth(self.view.frame) - 40, CGRectGetWidth(self.view.frame) - 140)];
    
    // 图片拉伸
    // UIImageResizingModeStretch 均匀拉伸
    // UIImageResizingModeTile 瓦片
    imageView.backgroundColor = [UIColor cyanColor];
    UIEdgeInsets edgeInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    image = [image resizableImageWithCapInsets:edgeInset resizingMode: UIImageResizingModeTile];
    
    imageView.image = image;
    [self.view addSubview:imageView];
    
    // 设置图片圆角
    imageView.layer.cornerRadius = 50;
    imageView.layer.borderWidth = 3.0;
    imageView.layer.borderColor = [UIColor blueColor].CGColor;
    // 裁剪
    imageView.clipsToBounds = YES;
    
    // 显示模式
    [imageView setContentMode:UIViewContentModeTop];
    
    [self.view addSubview:redView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
